package com.pearadmin.pro.modules.ser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pearadmin.pro.modules.ser.domain.ServerDept;
import com.pearadmin.pro.modules.ser.domain.dto.ServerDeptDto;
import com.pearadmin.pro.modules.ser.repository.ServerDeptRepository;
import com.pearadmin.pro.modules.ser.service.ServerDeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author: didiplus
 * Email: 972479352@qq.com
 * CreateTime: 2022/3/10
 * Desc:
 */
@Service
public class ServerDeptServiceImpl extends ServiceImpl<ServerDeptRepository, ServerDept> implements ServerDeptService {


    @Resource
    ServerDeptRepository serverDeptRepository;
    /**
     * 根据部门ID查询部门拥有的服务器列表
     * @param  deptId
     */
    @Override
    public List selectByDeptId(String deptId) {
        List<ServerDept> serverDepts = serverDeptRepository.selectList(new LambdaQueryWrapper<ServerDept>().eq(ServerDept::getDeptId,deptId));
        return serverDepts;
    }


    /**
     * 根据部门ID和服务器ID删除记录
     * @return
     */
    @Override
    public Boolean delete(ServerDeptDto serverDeptDto) {
        int delete = serverDeptRepository.delete(Wrappers.<ServerDept>lambdaQuery().eq(ServerDept::getDeptId, serverDeptDto.getDeptId()).in(ServerDept::getServerId, serverDeptDto.getServerIdList()));
        return  delete > 0 ? true:false;
    }
}
